\documentclass{article}

\usepackage[top=25mm,bottom=25mm,left=25mm,right=25mm]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{subfig}
\usepackage{epstopdf}
\usepackage{mcode}
\usepackage{maplestd2e}

\begin{document}

\title{ESP - Analog lab 4}
\author{Floris van Nee \& Simon Dirlik}

\maketitle

\section{} %1
The quantization error for a 15 MHz wideband signal with amplitude 2 can be seen as randomly distributed (referring to digital lab problem 1.2 for the difference in error between a sine and random signal). Thus, the average quantization error for a 1-bit quantizer is $\frac{1}{2}$. For a 10-bit quantizer this is $\frac{1}{2^{10}}$.

If instead of a wideband signal, a single sine wave is quantized, the quantization error is less. Because the absolute amplitude of a sine is more often close to 1 than closer to 0, the average quantization error will be less than $\frac{1}{2}$. When the original signal is much larger than one LSB (to avoid distortion), the following formula holds: $SNR = 1.76 + 6.02 \cdot n$ dB, where $n$ is the number of bits. For 10 bits, this is $61.96$ dB. Thus, this leads to an average error of $10^{\frac{-61.96}{10}} = 6.4\cdot 10^{-7}$.

\section{} %2
The Maple code to calculate the required OSR and corresponding frequency can be found below. The variable osr is the OSR for a loop filter order of 1 and osr2 is for a loop filter order 2. Because the required sample rate for loop filter order 1 is too high, order 2 is preferred. This has a sample rate of approximately 800 MHz.

\DefineParaStyle{Maple Heading 1}
\DefineParaStyle{Maple Text Output}
\DefineParaStyle{Maple Dash Item}
\DefineParaStyle{Maple Bullet Item}
\DefineParaStyle{Maple Normal}
\DefineParaStyle{Maple Heading 4}
\DefineParaStyle{Maple Heading 3}
\DefineParaStyle{Maple Heading 2}
\DefineParaStyle{Maple Warning}
\DefineParaStyle{Maple Title}
\DefineParaStyle{Maple Error}
\DefineCharStyle{Maple Hyperlink}
\DefineCharStyle{Maple 2D Math}
\DefineCharStyle{Maple Maple Input}
\DefineCharStyle{Maple 2D Output}
\DefineCharStyle{Maple 2D Input}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{restart;
}{}
\end{mapleinput}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{max_noise := 0.5e-6;
}{}
\end{mapleinput}
\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{max_noise := 5.*10^(-7)}{\[\displaystyle {\it max\_noise}\, := \, 0.0000005000000000\]}
\end{maplelatex}
\end{maplegroup}
\begin{maplegroup}
\begin{Maple Normal}{
Maximum noise is determined by S/N = 10\symbol{94}6, with S=1/2}\end{Maple Normal}

\begin{Maple Normal}{
}\end{Maple Normal}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{sigmadelta := no = (Pi\symbol{94}(2*N)*epsilon\symbol{94}2) / ((1+2*N) * OSR\symbol{94}(2*N+1));
}{}
\end{mapleinput}
\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{sigmadelta := no = Pi^(2*N)*epsilon^2/((1+2*N)*OSR^(1+2*N))}{\[\displaystyle {\it sigmadelta}\, := \,{\it no}={\frac {{\pi }^{2\,N}{\epsilon}^{2}}{ \left( 1+2\,N \right) {{\it OSR}}^{1+2\,N}}}\]}
\end{maplelatex}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{vals := [N=1, no=0.5e-6, epsilon\symbol{94}2=1/3];
}{}
\end{mapleinput}
\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{vals := [N = 1, no = 5.*10^(-7), epsilon^2 = 1/3]}{\[\displaystyle {\it vals}\, := \,[N=1,{\it no}= 0.0000005000000000\\
\mbox{},{\epsilon}^{2}=1/3]\]}
\end{maplelatex}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{osr := evalf(solve(subs(vals,sigmadelta), OSR))[1];
}{}
\end{mapleinput}
\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{osr := 129.9259030}{\[\displaystyle {\it osr}\, := \, 129.9259030\]}
\end{maplelatex}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{osr*30e6;
}{}
\end{mapleinput}
\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{3.897777090*10^9}{\[\displaystyle  3897777090.0\]}
\end{maplelatex}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{vals := [N=2, no=0.5e-6, epsilon\symbol{94}2=1/3];}{}
\end{mapleinput}
\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{vals := [N = 2, no = 5.*10^(-7), epsilon^2 = 1/3]}{\[\displaystyle {\it vals}\, := \,[N=2,{\it no}= 0.0000005000000000\\
\mbox{},{\epsilon}^{2}=1/3]\]}
\end{maplelatex}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{osr2:=evalf(solve(subs(vals,sigmadelta), OSR))[1];}{}
\end{mapleinput}
\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{osr2 := 26.46717845}{\[\displaystyle {\it osr2}\, := \, 26.46717845\]}
\end{maplelatex}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{osr2*30e6;
}{}
\end{mapleinput}
\mapleresult
\begin{maplelatex}
\mapleinline{inert}{2d}{7.940153535*10^8}{\[\displaystyle  794015353.5\]}
\end{maplelatex}
\end{maplegroup}
\begin{maplegroup}
\begin{mapleinput}
\mapleinline{active}{1d}{}{}
\end{mapleinput}
\end{maplegroup}

\section{} %3
The scope output of the simulation can be found in figure \ref{fig:scope}. This output was verified to be correct.

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{scope.png}
	\caption{The scope output of the simulation results}
	\label{fig:scope}
\end{figure}

\section{} %4
The Matlab script that was used to calculate the SINAD can be found in the following section.

\begin{lstlisting}
nfft=size(SD_2,1);
kw=kaiser(nfft,20);
fs=7.94e8;
b=15e6;

p=pwelch(SD_2,kw,[],nfft,fs);
loglog(p);

t=1/(b/nfft);
b2=b/(fs/nfft);

signal=sum(p(28:41)) % signal
noise=sum(p(1:round(b2)))-signal % noise
10*log10(signal/noise)

% 3.3333e-005
\end{lstlisting}

A Kaiser window with a value of 20 was used. This makes the peak at 1 MHz well visible and makes it easy to calculate the ratio between the signal and noise, by just taking the sum of the points for the 1 MHz signal and dividing that by the sum of the points in the interval 0-15MHz except the 1 MHz signal.

The output of the pwelch plot can be found in figure \ref{fig:fft}. The calculated SINAD is 51 dB. This is roughly equal to the calculated 60 dB.

\begin{figure}
	\centering
		\includegraphics[width=1.00\textwidth]{fft.eps}
	\caption{The plot of the output of pwelch on the simulation results}
	\label{fig:fft}
\end{figure}

\end{document}
